<template>
  <Back />
  <div class="bg-#fafafa min-h-100vh p-t-20px">
    <div class="box items-center">
      <div class="font-size-1.6rem">
        {{ [$t('shop.take.make'), $t('shop.take.take'), $t('shop.take.done')][status] }}
      </div>
      <div class="font-size-3.2rem m-y-6px">
        <div>{{ order?.delivery }}</div>
      </div>
      <div class="font-size-1.4rem color-#666666">{{ $t('shop.take.number') }}</div>
    </div>

    <div class="box">
      <div class="font-size-1.6rem bt p-b10px">{{ order?.shopName }}</div>
      <div class="m-t10px">
        <template v-if="order.type == 10">
          <div class="product" v-for="p in order.productInfo">
            <div class="flex items-center">
              <img :src="p.productImg" />
              <div>
                <div class="font-size-1.4rem color-#333 m-b6px">{{ showName(p) }}</div>
                <div class="font-size-1.2rem color-#666">{{ p.size }}/{{ showCold(p.cold!) }}/{{ showSugar(p.sugar!) }}</div>
              </div>
            </div>
            <div>
              <div class="font-size-2rem color-#333 m-b6px">{{ p.price }}</div>
              <div class="font-size-1.2rem color-#666">x{{ p.amount }}</div>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="font-size-1.6rem">{{ orderType(order.type) }}</div>
        </template>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const order = ref<ApiOrders>({} as ApiOrders)

const route = useRoute()
const router = useRouter()

onMounted(() => {
  const orderNum = (route.query && route.query.num) as string

  if (orderNum) {
    apis.api.userOrderOrder({ num: orderNum }).then(d => {
      order.value = d
    })
  } else {
    router.replace('/home')
  }
})

const status = computed(() => orderStatusWithTime(order.value.status, order.value.createTime))
</script>
<style lang="scss" scoped>
.box {
  margin: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  box-shadow: 0rem 0rem 1.93rem 0rem rgba(0, 0, 0, 0.04);
  border-radius: 1.2rem;
}

.bt {
  border-bottom: 1px solid #dcdcdc;
}

.product {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  &:last-child {
    margin-bottom: 0;
  }
  img {
    width: 60px;
    height: 60px;
    margin-right: 14px;
    border-radius: 4px;
  }
}
</style>
